/////////////////////////////////////////////////////////////////////////////
// Name:        slposconfig.cpp
// Purpose:     
// Author:      Herry Ayen Yang
// Modified by: 
// Created:     26/02/2009 17:00:46
// RCS-ID:      
// Copyright:   Copyright (c) 2000, 2008 Krida Software Division
// Licence:     
/////////////////////////////////////////////////////////////////////////////

// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"

#ifdef __BORLANDC__
#pragma hdrstop
#endif

#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif

////@begin includes
////@end includes

#include "slposconfig.h"

////@begin XPM images
////@end XPM images


/*!
 * SLposConfig type definition
 */

IMPLEMENT_DYNAMIC_CLASS( SLposConfig, wxDialog )


/*!
 * SLposConfig event table definition
 */

BEGIN_EVENT_TABLE( SLposConfig, wxDialog )

////@begin SLposConfig event table entries
    EVT_BUTTON( wxID_CANCEL, SLposConfig::OnCancelClick )

    EVT_BUTTON( wxID_SAVE, SLposConfig::OnSaveClick )

////@end SLposConfig event table entries

END_EVENT_TABLE()


/*!
 * SLposConfig constructors
 */

SLposConfig::SLposConfig()
{
    Init();
}

SLposConfig::SLposConfig( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
{
    Init();
    Create(parent, id, caption, pos, size, style);
}


/*!
 * SLposConfig creator
 */

bool SLposConfig::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
{
////@begin SLposConfig creation
    SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
    wxDialog::Create( parent, id, caption, pos, size, style );

    CreateControls();
    if (GetSizer())
    {
        GetSizer()->SetSizeHints(this);
    }
    Centre();
////@end SLposConfig creation
    return true;
}


/*!
 * SLposConfig destructor
 */

SLposConfig::~SLposConfig()
{
////@begin SLposConfig destruction
////@end SLposConfig destruction
}


/*!
 * Member initialisation
 */

void SLposConfig::Init()
{
////@begin SLposConfig member initialisation
////@end SLposConfig member initialisation
    config = new wxConfig(wxT("slpos"));
    
    ServerAddress   = config->Read(wxT("ServerAddress"), wxT("127.0.0.1"));
    ServerPort      = config->Read(wxT("ServerPort"), wxT("5432"));
    DatabaseName    = config->Read(wxT("DatabaseName"), wxT(""));
    Username       = config->Read(wxT("DBlogin"), wxT(""));
    Password       = config->Read(wxT("DBpass"), wxT(""));
}


/*!
 * Control creation for SLposConfig
 */

void SLposConfig::CreateControls()
{    
////@begin SLposConfig content construction
    SLposConfig* itemDialog1 = this;

    wxStaticBox* itemStaticBoxSizer2Static = new wxStaticBox(itemDialog1, wxID_ANY, _("Database"));
    wxStaticBoxSizer* itemStaticBoxSizer2 = new wxStaticBoxSizer(itemStaticBoxSizer2Static, wxVERTICAL);
    itemDialog1->SetSizer(itemStaticBoxSizer2);

    wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
    itemStaticBoxSizer2->Add(itemBoxSizer3, 0, wxGROW|wxLEFT|wxRIGHT, 5);

    wxStaticText* itemStaticText4 = new wxStaticText( itemDialog1, wxID_STATIC, _("Server Address:"), wxDefaultPosition, wxSize(100, -1), 0 );
    itemBoxSizer3->Add(itemStaticText4, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxTextCtrl* itemTextCtrl5 = new wxTextCtrl( itemDialog1, ID_TEXTCTRL, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
    itemBoxSizer3->Add(itemTextCtrl5, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxBoxSizer* itemBoxSizer6 = new wxBoxSizer(wxHORIZONTAL);
    itemStaticBoxSizer2->Add(itemBoxSizer6, 0, wxGROW|wxLEFT|wxRIGHT, 5);

    wxStaticText* itemStaticText7 = new wxStaticText( itemDialog1, wxID_STATIC, _("Server Port:"), wxDefaultPosition, wxSize(100, -1), 0 );
    itemBoxSizer6->Add(itemStaticText7, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxTextCtrl* itemTextCtrl8 = new wxTextCtrl( itemDialog1, ID_TEXTCTRL1, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
    itemBoxSizer6->Add(itemTextCtrl8, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxBoxSizer* itemBoxSizer9 = new wxBoxSizer(wxHORIZONTAL);
    itemStaticBoxSizer2->Add(itemBoxSizer9, 0, wxGROW|wxLEFT|wxRIGHT, 5);

    wxStaticText* itemStaticText10 = new wxStaticText( itemDialog1, wxID_STATIC, _("Database Name:"), wxDefaultPosition, wxSize(100, -1), 0 );
    itemBoxSizer9->Add(itemStaticText10, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxTextCtrl* itemTextCtrl11 = new wxTextCtrl( itemDialog1, ID_TEXTCTRL2, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
    itemBoxSizer9->Add(itemTextCtrl11, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxStaticLine* itemStaticLine12 = new wxStaticLine( itemDialog1, wxID_STATIC, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
    itemStaticBoxSizer2->Add(itemStaticLine12, 0, wxGROW|wxALL, 5);

    wxBoxSizer* itemBoxSizer13 = new wxBoxSizer(wxHORIZONTAL);
    itemStaticBoxSizer2->Add(itemBoxSizer13, 0, wxGROW|wxLEFT|wxRIGHT, 5);

    wxStaticText* itemStaticText14 = new wxStaticText( itemDialog1, wxID_STATIC, _("Username:"), wxDefaultPosition, wxSize(100, -1), 0 );
    itemBoxSizer13->Add(itemStaticText14, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxTextCtrl* itemTextCtrl15 = new wxTextCtrl( itemDialog1, ID_TEXTCTRL3, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
    itemBoxSizer13->Add(itemTextCtrl15, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxBoxSizer* itemBoxSizer16 = new wxBoxSizer(wxHORIZONTAL);
    itemStaticBoxSizer2->Add(itemBoxSizer16, 0, wxGROW|wxLEFT|wxRIGHT, 5);

    wxStaticText* itemStaticText17 = new wxStaticText( itemDialog1, wxID_STATIC, _("Password:"), wxDefaultPosition, wxSize(100, -1), 0 );
    itemBoxSizer16->Add(itemStaticText17, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxTextCtrl* itemTextCtrl18 = new wxTextCtrl( itemDialog1, ID_TEXTCTRL4, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PASSWORD );
    itemBoxSizer16->Add(itemTextCtrl18, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxStaticLine* itemStaticLine19 = new wxStaticLine( itemDialog1, wxID_STATIC, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
    itemStaticBoxSizer2->Add(itemStaticLine19, 0, wxGROW|wxALL, 5);

    wxStdDialogButtonSizer* itemStdDialogButtonSizer20 = new wxStdDialogButtonSizer;

    itemStaticBoxSizer2->Add(itemStdDialogButtonSizer20, 0, wxGROW|wxALL, 5);
    wxButton* itemButton21 = new wxButton( itemDialog1, wxID_CANCEL, _("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
    itemStdDialogButtonSizer20->AddButton(itemButton21);

    wxButton* itemButton22 = new wxButton( itemDialog1, wxID_SAVE, _("&Save"), wxDefaultPosition, wxDefaultSize, 0 );
    itemButton22->SetDefault();
    itemStdDialogButtonSizer20->AddButton(itemButton22);

    itemStdDialogButtonSizer20->Realize();

    // Set validators
    itemTextCtrl5->SetValidator( wxTextValidator(wxFILTER_NONE, & ServerAddress) );
    itemTextCtrl8->SetValidator( wxTextValidator(wxFILTER_NONE, & ServerPort) );
    itemTextCtrl11->SetValidator( wxTextValidator(wxFILTER_NONE, & DatabaseName) );
    itemTextCtrl15->SetValidator( wxTextValidator(wxFILTER_NONE, & Username) );
    itemTextCtrl18->SetValidator( wxTextValidator(wxFILTER_NONE, & Password) );
////@end SLposConfig content construction
}


/*!
 * Should we show tooltips?
 */

bool SLposConfig::ShowToolTips()
{
    return true;
}

/*!
 * Get bitmap resources
 */

wxBitmap SLposConfig::GetBitmapResource( const wxString& name )
{
    // Bitmap retrieval
////@begin SLposConfig bitmap retrieval
    wxUnusedVar(name);
    return wxNullBitmap;
////@end SLposConfig bitmap retrieval
}

/*!
 * Get icon resources
 */

wxIcon SLposConfig::GetIconResource( const wxString& name )
{
    // Icon retrieval
////@begin SLposConfig icon retrieval
    wxUnusedVar(name);
    return wxNullIcon;
////@end SLposConfig icon retrieval
}


/*!
 * wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_CANCEL
 */

void SLposConfig::OnCancelClick( wxCommandEvent& event )
{
    wxUnusedVar(event);
////@begin wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_CANCEL in SLposConfig.
    // Before editing this code, remove the block markers.
    EndModal(wxID_CANCEL);
////@end wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_CANCEL in SLposConfig. 
}


/*!
 * wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_SAVE
 */

void SLposConfig::OnSaveClick( wxCommandEvent& event )
{
    wxUnusedVar(event);
    if( Validate() && TransferDataFromWindow()) {
        config->Write("ServerAddress", ServerAddress);
        config->Write("ServerPort", ServerPort);
        config->Write("DatabaseName", DatabaseName);
        config->Write("DBlogin", Username);
        config->Write("DBpass", Password);
        EndModal(wxID_SAVE);
    };
}
